package cn.snmp.mutual.uk.stack;

class TimeWindowNode {
    private static final String version_id = "@(#)$Id: TimeWindowNode.java,v 3.10 2006/01/17 17:43:54 birgit Exp $ Copyright Westhawk Ltd";
    public static final int maxTime = Integer.MAX_VALUE;
    private String snmpEngineId;
    private int snmpEngineBoots;
    private int snmpEngineTime;
    private int latestReceivedEngineTime;

    public TimeWindowNode(final String engId) {
        this(engId, 0, 0);
    }

    public TimeWindowNode(final String engId, final int boots, final int time) {
        this.snmpEngineBoots = 0;
        this.snmpEngineTime = 0;
        this.latestReceivedEngineTime = 0;
        this.snmpEngineId = engId;
        this.snmpEngineBoots = boots;
        this.snmpEngineTime = time;
        this.latestReceivedEngineTime = time;
    }

    public String getSnmpEngineId() {
        return this.snmpEngineId;
    }

    public void setSnmpEngineBoots(final int newSnmpEngineBoots) {
        this.snmpEngineBoots = newSnmpEngineBoots;
    }

    public int getSnmpEngineBoots() {
        return this.snmpEngineBoots;
    }

    public void setSnmpEngineTime(final int newSnmpEngineTime) {
        this.snmpEngineTime = newSnmpEngineTime;
        this.latestReceivedEngineTime = newSnmpEngineTime;
    }

    public int getSnmpEngineTime() {
        return this.snmpEngineTime;
    }

    public synchronized void incrementSnmpEngineTime(final int incr) {
        this.snmpEngineTime += incr;
        if (this.snmpEngineTime > Integer.MAX_VALUE) {
            ++this.snmpEngineBoots;
            this.snmpEngineTime -= Integer.MAX_VALUE;
        }
    }

    public int getLatestReceivedEngineTime() {
        return this.latestReceivedEngineTime;
    }

    @Override
    public String toString() {
        final StringBuffer buffer = new StringBuffer(this.getClass().getName());
        buffer.append("[");
        buffer.append("engineId=").append(this.snmpEngineId);
        buffer.append(", engineBoots=").append(this.snmpEngineBoots);
        buffer.append(", engineTime=").append(this.snmpEngineTime);
        buffer.append(", latestReceivedEngineTime=").append(this.latestReceivedEngineTime);
        buffer.append("]");
        return buffer.toString();
    }
}
